#include "ipsetdialog.h"
#include "ui_ipsetdialog.h"

IpSetDialog::IpSetDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::IpSetDialog)
{
    ui->setupUi(this);
    this->setStyleSheet("outline: none;");            //无虚线框
    this->setWindowFlags(Qt::FramelessWindowHint);    //无边框

    isEditing = false;
    hide();
}

IpSetDialog::~IpSetDialog()
{
    delete ui;
}

void IpSetDialog::changeLanguage()
{
    ui->retranslateUi(this);//mark
}

void IpSetDialog::on_sureBtn_clicked()
{
    QString ip = "";
    ip = ui->hmi1_lineEdit->text() +"."+
            ui->hmi2_lineEdit->text() +"."+
            ui->hmi3_lineEdit->text() +"."+
            ui->hmi4_lineEdit->text();
    emit hmiIpSettingSignal(ip);
    this->close();
}

void IpSetDialog::on_cancelBtn_clicked()
{
    this->close();
}

void IpSetDialog::on_hmi1_lineEdit_cursorPositionChanged(int arg1, int arg2)
{
    if(!isEditing)
    {
       ui->hmi1_lineEdit->selectAll();
    }
}

void IpSetDialog::on_hmi2_lineEdit_cursorPositionChanged(int arg1, int arg2)
{
    if(!isEditing)
    {
        ui->hmi2_lineEdit->selectAll();
    }
}

void IpSetDialog::on_hmi3_lineEdit_cursorPositionChanged(int arg1, int arg2)
{
    if(!isEditing)
    {
        ui->hmi3_lineEdit->selectAll();
    }
}

void IpSetDialog::on_hmi4_lineEdit_cursorPositionChanged(int arg1, int arg2)
{
    if(!isEditing)
    {
        ui->hmi4_lineEdit->selectAll();
    }
}

void IpSetDialog::on_hmi4_lineEdit_editingFinished()
{
    isEditing = false;
}

void IpSetDialog::on_hmi3_lineEdit_editingFinished()
{
    isEditing = false;
}

void IpSetDialog::on_hmi2_lineEdit_editingFinished()
{
    isEditing = false;
}

void IpSetDialog::on_hmi1_lineEdit_editingFinished()
{
    isEditing = false;
}

void IpSetDialog::on_hmi1_lineEdit_textEdited(const QString &arg1)
{
    isEditing = true;
}

void IpSetDialog::on_hmi2_lineEdit_textEdited(const QString &arg1)
{
    isEditing = true;
}

void IpSetDialog::on_hmi3_lineEdit_textEdited(const QString &arg1)
{
    isEditing = true;
}

void IpSetDialog::on_hmi4_lineEdit_textEdited(const QString &arg1)
{
    isEditing = true;
}
